package com.bruce.pattern.structural.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by bruce on 2018/11/9 21:10
 */
public class JdkDBQueryHandler implements InvocationHandler {
    private DBQueryI target = null;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        /*System.out.println("jdk invoke call");
        System.out.println(proxy.getClass().getName());
        System.out.println(method.getName());*/
        //不能保证DBQueryImpl对象是单例的
        if (target == null) {
            target = new DBQueryImpl();
        }
        return method.invoke(target, args);
    }
}